package chess;

import gui.PiecesUI;

import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

public class Board {
	final int EDGE = 8;
	Square board[][];

	List<Piece> inGamePieces = new ArrayList<Piece>();

	public Board(int[] b) {
		board = new Square[EDGE][EDGE];
		for (int i = 0; i < EDGE; i++) {
			for (int j = 0; j < EDGE; j++) {
				Color squareColor = (i % 2 == 0 ^ j % 2 == 0) ? Color.BLACK : Color.WHITE;
				switch (b[i * 8 + j]) {
				case PiecesUI.WHITE_PAWN:
					board[i][j] = new Square(new Piece(i, j, PIECETYPE.PAWN, Color.WHITE), squareColor);
					break;
				case PiecesUI.WHITE_KNIGHT:
					board[i][j] = new Square(PIECETYPE.KNIGHT, Color.WHITE);
					break;
				case PiecesUI.WHITE_BISHOP:
					board[i][j] = new Square(PIECETYPE.BISHOP, Color.WHITE);
					break;
				case PiecesUI.WHITE_QUEEN:
					board[i][j] = new Square(PIECETYPE.QUEEN, Color.WHITE);
					break;
				case PiecesUI.WHITE_KING:
					board[i][j] = new Square(PIECETYPE.KING, Color.WHITE);
					break;
				case PiecesUI.BLACK_PAWN:
					board[i][j] = new Square(PIECETYPE.PAWN, Color.BLACK);
					break;
				case PiecesUI.BLACK_KNIGHT:
					board[i][j] = new Square(PIECETYPE.KNIGHT, Color.BLACK);
					break;
				case PiecesUI.BLACK_BISHOP:
					board[i][j] = new Square(PIECETYPE.BISHOP, Color.BLACK);
					break;
				case PiecesUI.BLACK_QUEEN:
					board[i][j] = new Square(PIECETYPE.QUEEN, Color.BLACK);
					break;
				case PiecesUI.BLACK_KING:
					board[i][j] = new Square(PIECETYPE.KING, Color.BLACK);
					break;
				default:
					board[i][j] = new Square();
					break;
				}
			}
		}
	}

	public Board(boolean init) {
		board = new Square[EDGE][EDGE];
		for (int i = 0; i < EDGE; i++) {
			for (int j = 0; j < EDGE; j++) {
				if (i == 1) {
					board[i][j] = new Square(PIECETYPE.PAWN, Color.BLACK);
				} else if (i == 6) {
					board[i][j] = new Square(PIECETYPE.PAWN, Color.WHITE);
				}
			}
		}
	}

	public Board() {
		board = new Square[EDGE][EDGE];
		for (int i = 0; i < EDGE; i++) {
			for (int j = 0; j < EDGE; j++) {
				if (i % 2 == 0 ^ j % 2 == 0) {
					board[i][j] = new Square(null, Color.BLACK);
				} else {
					board[i][j] = new Square(null, Color.WHITE);
				}
			}
		}
	}

	// COLOR Black, White;

	public enum PIECETYPE {
		PAWN(1), ROOK(5), KNIGHT(3), BISHOP(3), QUEEN(9), KING(Integer.MAX_VALUE);
		int weight;

		private PIECETYPE(int weight) {
			this.weight = weight;
		}
	}

	private void scan() {
		for (int i = 0; i < EDGE; i++) {
			for (int j = 0; j < EDGE; j++) {
				Square sq = board[i][j];
				if (sq.piece != null) {
					possibleMoves(sq.piece);
				}
			}
		}
	}

	private void possibleMoves(PIECETYPE piece) {
		// TODO Auto-generated method stub

	}

	private void print() {
		for (int i = 0; i < EDGE; i++) {
			for (int j = 0; j < EDGE; j++) {
				System.out.print(board[i][j] + "\t");
			}
			System.out.println("\n");
		}
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}
}